package com.sczmgk.hotline_pzh.base;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

public abstract class BasicAdapter<T> extends BaseAdapter {

    public List<T> mList;
    private int mLayoutId;

    /**
     * 数据和布局
     */
    public BasicAdapter(List<T> list, int layoutId) {
        super();
        mList = list;
        mLayoutId = layoutId;
    }

    @Override
    public int getCount() {
        return this.mList == null ? 0 : this.mList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        T value = mList.get(position);
        Object hd = null;
        if (convertView == null) {
            convertView = View.inflate(parent.getContext(), mLayoutId, null);
            hd = createViewHolder(position, convertView);///////////////////////////////////////
            convertView.setTag(hd);
        } else {
            hd = (Object) convertView.getTag();
        }
        setItemData(position, value, hd);
        return convertView;
    }

    protected abstract void setItemData(int position, T value, Object hd);

    protected abstract Object createViewHolder(int position, View convertView);


}
